package com.homework;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Objects;

public class homework2 {
    /*
    一、	请按以下要求编写代码：
    1.	定义Student类，包含以下属性：
        学号、姓名、身高
    2.	定义MainApp类，包含main()方法；
    3.	在main()方法中，创建一个可以存储Student对象的集合对象；
    4.	创建以下几个Student对象：
        学号		姓名		身高
        it001	黄渤		1.72
        it002	孙红雷	1.78
        it003	章子怡	1.64
        it004	杨颖		1.68
    5.	将上面几个对象添加到集合中
    6.	遍历集合打印每个对象的属性值；
    7.	获取并打印集合大小；
    8.	获取第3个学员对象，并打印其属性值；
    9.	移除掉第4个学员对象；
    10.	再次获取并打印集合大小；
    11.	将第一个对象替换为以下对象：
        it005	撒贝宁	1.67
    12.	遍历集合，打印出身高在1.70以上的学员信息；
    13.	遍历集合，打印出“孙”姓的学员信息；
     */
    public static void main(String[] args) {
        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student1 = new Student("it001","黄渤",new BigDecimal(1.72).setScale(2, RoundingMode.HALF_UP));
        Student student2 = new Student("it002","孙红雷",new BigDecimal(1.78).setScale(2, RoundingMode.HALF_UP));
        Student student3 = new Student("it003","章子怡",new BigDecimal(1.64).setScale(2, RoundingMode.HALF_UP));
        Student student4 = new Student("it004","杨颖",new BigDecimal(1.68).setScale(2, RoundingMode.HALF_UP));
        studentArrayList.add(student1);
        studentArrayList.add(student2);
        studentArrayList.add(student3);
        studentArrayList.add(student4);
        for (Student student : studentArrayList) {
            System.out.println(student);
        }
        System.out.println(studentArrayList.size());
        System.out.println(studentArrayList.get(2));
        System.out.println("======================================================");
        studentArrayList.remove(3);
        Student student5 = new Student("it005","撒贝宁",new BigDecimal(1.67).setScale(2, RoundingMode.HALF_UP));
        studentArrayList.set(0,student5);
        for (Student student : studentArrayList) {
            if (student.getHeight().compareTo(new BigDecimal(1.70).setScale(2, RoundingMode.HALF_UP)) == 1){
                System.out.println("身高在1.70以上的学员信息；" + student);
            }
        }
        System.out.println("======================================================");
        for (Student student : studentArrayList) {
            if (student.getName().contains("孙")){
                System.out.println("孙姓的学员信息；" + student);
            }
        }
    }
}
class Student{
    private String id;
    private String name;
    private BigDecimal height;

    public Student() {
    }

    public Student(String id, String name, BigDecimal height) {
        this.id = id;
        this.name = name;
        this.height = height;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public void setHeight(BigDecimal height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", height=" + height +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;
        return Objects.equals(id, student.id) && Objects.equals(name, student.name) && Objects.equals(height, student.height);
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(id);
        result = 31 * result + Objects.hashCode(name);
        result = 31 * result + Objects.hashCode(height);
        return result;
    }
}